package test.yzx.pproject;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import com.transitionseverywhere.ChangeBounds;
import com.transitionseverywhere.Scene;
import com.transitionseverywhere.Slide;
import com.transitionseverywhere.TransitionManager;

public class TransitionActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.l1);

        singleViewTransition2();

    }


    private void allLayoutChange(){
        getWindow().getDecorView().postDelayed(new Runnable() {
            public void run() {
                Scene s1 = Scene.getSceneForLayout((ViewGroup) findViewById(R.id.layout11), R.layout.test_transition_layout, TransitionActivity.this);
                Slide slide = new Slide();
                slide.setDuration(600);
                TransitionManager.go(s1, slide);
            }
        }, 500);
    }


    private void singleViewTransition(){
       getWindow().getDecorView().postDelayed(new Runnable() {
           public void run() {
               ChangeBounds cb = new ChangeBounds();
               cb.setDuration(500);
               TransitionManager.beginDelayedTransition((ViewGroup) findViewById(R.id.container));

               View view = findViewById(R.id.view);
               ViewGroup.LayoutParams lp = view.getLayoutParams();
               lp.height=lp.width = 50*3;
               view.requestLayout();
           }
       }, 500);

    }


    private void singleViewTransition2(){
        getWindow().getDecorView().postDelayed(new Runnable() {
            public void run() {
                final ChangeBounds cb = new ChangeBounds();
                cb.setDuration(500);
                TransitionManager.beginDelayedTransition((ViewGroup) findViewById(R.id.container), cb);

                final View view = findViewById(R.id.view);
                final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
                lp.topMargin = 100;

                final View view3 = findViewById(R.id.view3);
                view3.getLayoutParams().height=50;


                view.requestLayout();




                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        TransitionManager.beginDelayedTransition((ViewGroup) findViewById(R.id.container), cb);
                        lp.topMargin = 0;
                        view.requestLayout();
                    }
                },1200);
            }
        }, 2000);
    }

}
